import 'package:seedfour/app/models/api_response/api_response_entity.dart';

import '../../../generated/json/base/json_convert_content.dart';
import 'list_data_entity.g.dart';

ApiResponseEntity<T> $ApiResponseEntityFromJson<T>(Map<String, dynamic> json) {
  final ApiResponseEntity<T> apiResponseEntity = ApiResponseEntity<T>();

  final bool? success = jsonConvert.convert<bool>(json['success']);
  if (success != null) {
    apiResponseEntity.success = success;
  }

  final int? detail = jsonConvert.convert<int>(json['detail']);
  if (detail != null) {
    apiResponseEntity.detail = detail;
  }

  final ApiResponseError? error =
      jsonConvert.convert<ApiResponseError>(json['error']);
  if (error != null) {
    apiResponseEntity.error = error;
  }

  T? data;
  if (json['data'] != null) {
    if (T.toString().startsWith("ListDataEntity<")) {
      data = listDataFromJsonSingle<T>(json);
    } else {
      data = jsonConvert.convert<T>(json['data']);
    }
  }
  if (data != null) {
    apiResponseEntity.data = data;
  }

  return apiResponseEntity;
}

Map<String, dynamic> $ApiResponseEntityToJson(ApiResponseEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['success'] = entity.success;
  data['detail'] = entity.detail;
  data['error'] = entity.error?.toJson();
  data['data'] = entity.data;
  return data;
}

ApiResponseError $ApiResponseErrorFromJson(Map<String, dynamic> json) {
  final ApiResponseError apiResponseError = ApiResponseError();
  final String? code = jsonConvert.convert<String>(json['code']);
  if (code != null) {
    apiResponseError.code = code;
  }
  final String? message = jsonConvert.convert<String>(json['message']);
  if (message != null) {
    apiResponseError.message = message;
  }
  return apiResponseError;
}

Map<String, dynamic> $ApiResponseErrorToJson(ApiResponseError entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['code'] = entity.code;
  data['message'] = entity.message;
  return data;
}
